﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ch01
{
    public partial class Form8 : Form
    {
        //定义字段保存Form1窗体
        Form1 f1;

        public Form8()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //普通模式打开窗体

            if (f1 == null || f1.IsDisposed)
            {
                f1 = new Form1();
            }
            
            f1.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //模式化打开窗体
            f1 = new Form1();
            f1.ShowDialog();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //关闭新打开的窗体
            if (f1 == null || f1.IsDisposed)
            {
                MessageBox.Show("新窗体还没有打开呢！");
            }
            else
            {
                f1.Close();
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            //隐藏新打开的窗体
            f1.Hide();
        }
    }
}
